package com.hb;

import com.hb.config.KnightConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class DifferentApplicationContext {
    public ApplicationContext getApplicationContext(int num) {
        ApplicationContext context;
        if (num == 1) {
            // 在指定的文件系统路径下查找 knight.xml 文件
            context = new FileSystemXmlApplicationContext("D:\\ITBookSourceCode\\SpringInAction4\\Chapter_01\\src\\main\\resources\\knights.xml");
        } else if (num == 2) {
            // 在所有的类路径（包含 JAR 文件）下查找 knight.xml 文件
            context = new ClassPathXmlApplicationContext("knights.xml");
        } else {
            // 从 Java 配置中加载应用上下文
            context = new AnnotationConfigApplicationContext(KnightConfig.class);
        }

        return context;
    }
}
